<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="coinfaces">

        <title>零宽度空白字符</title>

    <link rel="stylesheet" href="../../theme/css/style.css">
    <link rel="stylesheet" href="../../theme/css/pygments.css">



</head>

<body>
    <div class="content">
<h1>零宽度空白字符</h1>    <p>
        under
            <a href="../../tags/text/">text</a>
            <a href="../../tags/low/">low</a>
    </p>
    <p>
        in <a href="../../categories/tech/">tech</a>
    </p>
    <p>Published: 2016-11-05</p>


    <p>零宽度空白字符（十六进制：<tt class="docutils literal">&amp;#x200B;</tt>，十进制：<tt class="docutils literal">&amp;#8203;</tt>）是一种看不见的空白字符，它是不可打印的字符，虽然没有宽度，但在设置了词间距调整的情况下会在分隔的不同单词间留出空白。</p>
<p>有的网页上插入了看不见的空白字符，如果直接复制会得到意料之外的内容，举个例子：</p>
<pre><code>testdir=`mktemp -d`
touch $testdir/CopyMe.txt
touch $testdir/Copy&#x200B;Me.&#8203;txt
ls $testdir</code></pre><p>运行上面的代码会看到两个“同名”文件共存在同一目录下，这个魔术的奥秘就是其中一个文件名中包含了零宽度空白字符。用户可以用命令<tt class="docutils literal">tr <span class="pre">-dc</span> <span class="pre">&quot;[:print:]&quot;</span></tt>过滤不可打印字符，以免它们带来麻烦。</p>
<p>如果想了解更多空白字符，可以参考<a class="reference external" href="http://blog.fenrir-inc.com/us/2012/02/web-designing-tips-nbsp-is-not-a-half-width-space.html">这篇文章</a>，里面列出了7种不同的空白字符：</p>
<table>
  <thead>
    <tr>
      <td>名称</td>
      <td>十进制</td>
      <td>十六进制</td>
      <td>效果</td>
      <td>说明</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td>||</td>
      <td>没有字符</td>
    </tr>
    <tr>
      <td></td>
      <td>&amp;#32;</td>
      <td>&amp;#x20;</td>
      <td>|&#32;|</td>
      <td>标准半宽空白字符</td>
    </tr>
    <tr>
      <td>&amp;nbsp;</td>
      <td>&amp;#160;</td>
      <td>&amp;#xA0;</td>
      <td>|&#160;|</td>
      <td>非换行空白字符</td>
    </tr>
    <tr>
      <td>&amp;ensp;</td>
      <td>&amp;#8194;</td>
      <td>&amp;#x2002;</td>
      <td>|&#8194;|</td>
      <td>与“n”同宽的空白字符</td>
    </tr>
    <tr>
      <td>&amp;emsp;</td>
      <td>&amp;#8195;</td>
      <td>&amp;#x2003;</td>
      <td>|&#8195;|</td>
      <td>与“m”同宽的空白字符</td>
    </tr>
    <tr>
      <td>&amp;thinsp;</td>
      <td>&amp;#8201;</td>
      <td>&amp;#x2009;</td>
      <td>|&#8201;|</td>
      <td>窄空白字符</td>
    </tr>
    <tr>
      <td></td>
      <td>&amp;#8203;</td>
      <td>&amp;#x200B;</td>
      <td>|&#8203;|</td>
      <td>0宽度空白字符</td>
    </tr>
    <tr>
      <td></td>
      <td>&amp;#12288;</td>
      <td>&amp;#x3000;</td>
      <td>|&#12288;|</td>
      <td>全宽空白字符</td>
    </tr>
  </tbody>
</table><p>（完）</p>

    </div>
<nav class="nav sidebar">
    <div class="siteinfo">
        <div class="sitename"><a href="../..">coinfaces</a></div>
        <div class="tagline">Another Side of Life</div>
    </div>

        <a href="../../categories/">categories</a>
        <a href="../..">&larr; Home</a>
</nav><footer class="footer">
    <span>
        &copy; jpli &middot;
        under <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">CC-BY-SA 4.0</a>
    </span>
    |
    <span>
        Powered by:
        <a href="http://blog.getpelican.com/">Pelican</a>
    </span>
</footer></body>
</html>